var utilsmd5 = require('../../utils/md5.js')
var app = getApp()
Page({
  data: {
    userInfo: {},
    arraydetail: [],
    pinId: 0,
    author: 'Lotus'
  },
  onShareAppMessage: function () {
    var that=this;
    return {
      title: app.globalData.shopName,
      path: '/pages/index/pindetail?fromInviteCode=' + app.globalData.myInviteCode +'pinId=' + that.data.pinId,
      success: function (res) {
        //console.log("转发成功");
      }
    }
  }, 
  getlist: function (pinId) {
    var that = this;
    var service = 'ProductPin.getProductGroupsInfo';
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, pinId: pinId },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        if (!res.data.data.code) {
          that.setData({
            arraydetail: res.data.data.info
          })
          that.createCanvas(res.data.data.info.pin_info.pinNumHave, res.data.data.info.pin_info.pinNum); 
        }
      },
    })
  },

  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode=options.fromInviteCode;
    }
    app.appstart();
    if (options.pinId) {
      that.setData({ pinId: options.pinId });
      that.getlist(options.pinId);
    }
    that.setData({ userInfo: app.globalData.userInfo });
  
  },
  createCanvas: function (short, totalP) {
    var cxt_arc = wx.createCanvasContext('canvasArc');
    var total=80;//总长度;
    var chaP = 80 * (short / totalP);
    var chaP = chaP+10;
    var only = total - chaP;
    cxt_arc.setLineWidth(12); //设置线宽 
    cxt_arc.setStrokeStyle('#FFC001');  //线颜色
    cxt_arc.setLineCap('round');
    cxt_arc.setLineJoin('bevel');
    cxt_arc.beginPath();//开始一个新的路径  
    cxt_arc.moveTo(10, 10);
    cxt_arc.lineTo(chaP, 10) //20   
    cxt_arc.stroke();//对当前路径进行描边  

    cxt_arc.setLineWidth(12);
    cxt_arc.setStrokeStyle('#d2d2d2');

    cxt_arc.setLineCap('round')
    cxt_arc.beginPath();//开始一个新的路径  
    cxt_arc.moveTo(chaP, 10)
    cxt_arc.lineTo(90, 10) //80

    cxt_arc.stroke();//对当前路径进行描边  
    cxt_arc.draw();  


   }
})